<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport"
          content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/assets/activity/vote/css/vote.css?ver={BEESCRM:$time}"/>
    <link rel="stylesheet" href="/assets/bower_components/sweetalert/lib/sweet-alert.css?v={BEESCRM:$time}">
    <link rel="stylesheet" href="/assets/activity/vote/css/default.css?ver={BEESCRM:$time}">
    <link rel="stylesheet" href="/assets/activity/vote/css/component.css?ver={BEESCRM:$time}">
	<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <title>{BEESCRM:$vote['title']}</title>
</head>
<body>
<div class="vote-wraper">
    <div class="vote-header">
        <!-- <img src="/assets/activity/shake/images/mtop.png"> -->
        <p>{BEESCRM:$vote['title']} </p>
    </div>
    <div class="vote-tips">
        <p>投票说明：</p>
        <p>{BEESCRM:$vote['desc']}</p>
        <input type="hidden" name="voteid" class="voteid" value="{BEESCRM:$vote['vote_id']}">
    </div>

    <if condition="$voteType eq 0">
        <!--投票文字-->
        <ul class="vote-item-list vote-only-description">
	        <div class="data1">
	            <volist name="optionInfo" id="vo" key="i">
	                <li>
	                    <div class="tb-mode">
	                        <div class="tb-cell item-index">{BEESCRM:$i}</div>
	                        <div class="tb-cell item-describ">{BEESCRM:$vo.option_title}</div>
	                        <div class="tb-cell item-btn <if condition="$vo['voted'] eq 0">canvote</if>"><a href="javascript:void(0);"
	                            <if condition="$vo['voted'] eq 1">class="isVoted"</if>
	                            data-num="{BEESCRM:$vo.be_voted_num}"><if condition="$vo.voted eq 1">已投票<br/>（{BEESCRM:$vo.be_voted_num}票）<else/>投票给TA<br/>（{BEESCRM:$vo.be_voted_num}票）</if></a></div>
	                        <input type="hidden" name="optionid" class="optionid" value="{BEESCRM:$vo.option_id}">
	                    </div>
	                </li>
	            </volist>
	        </div>
        </ul>
    <else/>
        <!--投票图文-->
        <!--<ul class="vote-item-list vote-img-description clearfix">
	        <div class="data2">
            <volist name="data['optionInfo']" id="vo" key="i">
                <li style="height: 248px;">
                    <div class="show-box" data-id="{BEESCRM:$vo.option_id}" data-modal="modal-1">
                        <div class="item-title"><span
                                class="item-index">{BEESCRM:$i}</span>{BEESCRM:$vo.option_title}
                        </div>
                        <div class="item-thumb"><img src="{BEESCRM:$vo.thumb}">
                        </div>
                    </div>
                    <div class="item-btn <if condition='$vo.voted eq 0'>canvote</if>">
	                    <a href="javascript:void(0);" style="padding:4px 0;" name="dovote"
                        <if condition="$vo.voted eq 1">class="isVoted"</if>
                        data-num="{BEESCRM:$vo.be_voted_num}"><if condition="$vo.voted eq 1">已投票<br/>（{BEESCRM:$vo.be_voted_num}票）<else/>投票给TA<br/>（{BEESCRM:$vo.be_voted_num}票）</if></a></div>
                    <input type="hidden" name="optionid" class="optionid" value="{BEESCRM:$vo.option_id}">
                </li>
            </volist>
	        </div>
        </ul>-->

        <div class="list-container clearfix" id="list-container">
            <volist name="optionInfo" id="vo" key="i">
                <div class="item">
                    <div class="show-box" data-id="{BEESCRM:$vo.option_id}" data-modal="modal-1">
                        <div class="item-title"><span class="item-index">{BEESCRM:$i}</span> {BEESCRM:$vo.option_title}</div>
                        <if condition="$vo.thumb">
                        	<div class="item-thumb"><img src="{BEESCRM:$vo.thumb}"/></div>
                        </if>
                    </div>
                    <div class='item-btn <eq name="vo.voted" value="0">canvote</eq>'>
                       <if condition="$vo['voted'] eq 1">
                       		<a href="javascript:void(0);" style="padding:4px 0;" name="dovote" class="isVoted" data-num="{BEESCRM:$vo.be_voted_num}">已投票</br>（{BEESCRM:$vo.be_voted_num}票）</a>
                       <else/>
                       		<a href="javascript:void(0);" style="padding:4px 0;" name="dovote"  data-num="{BEESCRM:$vo.be_voted_num}">投票给TA<br/>（{BEESCRM:$vo.be_voted_num}票）</a>
                       </if>
                    </div>
                    <input type="hidden" name="optionid" class="optionid" value="{BEESCRM:$vo.option_id}">
                </div>
            </volist>
        </div>
    </if>
    
    <p style="color: #999;text-align:center;padding-bottom:20px;display:none;" id="loadmore">正在努力加载中……</p>
    <if condition="$vote['subscribe_qrcode_url']">
	    <div style="width: 90%;margin: 0 auto;" id="qrcode">
	     <!-- <img src="/assets/activity/vote/image/qrcode.gif"/> -->
	        <img src="{BEESCRM:$vote['subscribe_qrcode_url']}"/>
	    </div>
    </if>
</div>
<input type="hidden" value="{BEESCRM:$pageCount}" id="pagecount">
<input type="hidden" value="{BEESCRM:$vote.vote_limit}" id="vote_limit">
<include file="commonJS"/>
<include file="share"/>
<!--模态窗-->
<div class="md-modal md-effect-1" id="modal-1">
    <div class="md-content">
        <div class="get-modal-content">
            <div class="inner-content"></div>
            <button class="md-close"><span class="iconfont icon-close"></span></button>
        </div>
    </div>
</div>
<div class="md-overlay"></div>
</body>
</html>
<script src="/assets/activity/vote/js/classie.js"></script>
<script src="/assets/activity/vote/js/modalEffects.js"></script>
<script src="/assets/activity/vote/js/vote.js?ver={BEESCRM:$time}"></script>
<script src="/assets/activity/vote/js/masonry.pkgd.min.js"></script>
<script src="/assets/activity/vote/js/imagesloaded.pkgd.min.js"></script>
<script>
    $(function(){
    	var voteLimit = $('#vote_limit').val();
        var page = 1;
        var pageCount = $("#pagecount").val();
        var vote_id = $(".voteid").val();
        $(window).scroll(function() {
            //当内容滚动到底部时加载新的内容
            if ($(window).scrollTop() + $(window).height() + 20 > $(document).height()) {
                //当前要加载的页码
                page++;
                if(page <= pageCount){
                    LoadPage(page, vote_id);
                }else{
                	if(voteLimit == 2){
                		 //$('#qrcode').show();
                		 location.hash = "#qrcode";
                	}
                }
            }
        });

        function LoadPage(page, vote_id){
            $.ajax({
                'url': "/activity/vote/getOption/vote_id/"+vote_id,
                'data': {p:page},
                'dataType':'json',
                'type': 'GET',
                'async': false,
                beforeSend:function(){
                    $('#loadmore').show();
                    $('.scrm-loadding').show();
                },
                success: function(info){
                    if(info.status == 'S'){
                        var type = info.voteType;
                        var optionInfo = info.optionInfo;
                        var str = '';
                        var num = (page - 1) * 8;
                        $(optionInfo).each(function(idx) {
                            var val = optionInfo[idx];
                            var canvote = '';
                            var isVoted = '';
                            var show1 = '';
                            if(val.voted == 0){
                                canvote = 'canvote';
                                show1 = '投票给TA<br/>('+val.be_voted_num+'票）';
                            }else{
                                show1 = '已投票<br/>('+val.be_voted_num+'票）';
                            }

                            if(val.voted == 1){
                                isVoted = 'class="isVoted"';
                            }

                            if(type == 0){   //文字投票
                                str = str+'<li><div class="tb-mode"><div class="tb-cell item-index">'+(num+idx+1)+'</div>'
                                +'<div class="tb-cell item-describ">'+val.option_title+'</div>'
                                +'<div class="tb-cell item-btn '+canvote+'"><a href="javascript:void(0);" '+isVoted+' data-num="'+val.be_voted_num+'">'+show1+'</a></div>'
                                +'<input type="hidden" name="optionid" class="optionid" value="'+val.option_id+'"></div></li>';
                            }else{
                                str += '<div class="item"><div class="show-box" data-id="'+val.option_id+'" data-modal="modal-1">'
                                    +'<div class="item-title"><span class="item-index">'+(num+idx+1)+'</span>'+val.option_title+'</div>';
                                    if(val.thumb){
                                    	str	+= '<div class="item-thumb"><img src="'+val.thumb+'"></div>';
                                    }
                                str	+= '</div><div class="item-btn '+canvote+'">'
                                    +'<a href="javascript:void(0);" style="padding:4px 0;" name="dovote" '+isVoted+' data-num="'+val.be_voted_num+'">'+show1+'</a></div>'
                                    +'<input type="hidden" name="optionid" class="optionid" value="'+val.option_id+'"></div>';
                            }
                        });

                        if(type == 0){
	                        $('.data1').append(str);
                        }else{
                            var $newElems = $(str).appendTo(container);
                            $newElems.imagesLoaded(function(){
//                                $newElems.animate({ opacity: 1},100);
                                container.masonry( 'appended', $newElems,true);
                            });
                        }
	                    $('.scrm-loadding').hide();
                        $('#loadmore').hide();
                    }
                }
            });
        }
    });

    var container = $('#list-container');
    container.imagesLoaded(function(){
        container.masonry({
            itemSelector : '.item',
            isAnimated: true
        });
    });
</script>
